<template>
  <div class="IndustryThinkTank">
    <!-- 内容区域 -->
    <section class="content-section">
      <!-- 筛选区域 -->
      <section class="filter-section">
        <div class="filter">
          <!-- 地域筛选 -->
          <div class="filter-item-region">
            <span class="filter-label">地域:</span>
            <div class="button-group">
              <!-- 所有地区按钮 -->
              <button :class="{'active': selectedRegion === 'ALL'}" @click="selectRegion('ALL')">
                {{ $t('IndustryThinkTank.All') }}
              </button>
              <!-- 国际地区按钮 -->
              <button :class="{'active': selectedRegion === 'INTERNATIONAL'}" @click="selectRegion('INTERNATIONAL')">
                {{ $t('IndustryThinkTank.International') }}
              </button>
              <!-- 中国地区按钮 -->
              <button :class="{'active': selectedRegion === 'CHINA'}" @click="selectRegion('CHINA')">
                {{ $t('IndustryThinkTank.China') }}
              </button>
            </div>
          </div>
          <!-- 国家/省份筛选 -->
          <div class="filter-item-country">
            <span class="filter-label">国家/省份:</span>
            <div class="button-group">
              <!-- 国家/省份按钮 -->
              <button v-for="country in filteredCountries"
                      :key="country.value"
                      :class="{'active': selectedCountry === country.value}"
                      @click="selectCountry(country.value)">
                {{ $t(`IndustryThinkTank.${country.text}`) }}
              </button>
            </div>
          </div>
        </div>
      </section>
      <!-- 显示内容区域 -->
      <div class="container">
        <div class="grid lg:grid-cols-3 gap-8">
          <!-- 卡片列表 -->
          <div v-for="item in filteredItems" :key="item.hospital">
            <div class="card">
              <div class="card-image">
                <img :src="item.imageSrc" alt="Card Image" class="image">
              </div>
              <div class="card-content">
                <div class="location">
                  <!-- 医院名称 -->
                  <span class="hospital">{{ $t(`IndustryThinkTank.${item.hospital}`) }}</span>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>
  </div>
</template>

<script>
export default {
  name: 'IndustryThinkTankIsLogin',
  data() {
    return {
      // 选中的地域
      selectedRegion: 'ALL',
      // 选中的国家/省份
      selectedCountry: 'ALL',
      // 国家/省份数据
      countries: [
        { value: 'ALL', text: 'All' },
        { value: 'UK', text: 'UK' },
        { value: 'HK', text: 'HK' },
        { value: 'GD', text: 'GD' }
      ],
      // 医院数据
      items: [
        { hospital: 'jianqiao', imageSrc: require('@/assets/IndustryThinkTank/Tank1.png'), match: {regions: ['INTERNATIONAL'], countries: ['UK']} },
        { hospital: 'lundun', imageSrc: require('@/assets/IndustryThinkTank/Tank2.png'), match: {regions: ['INTERNATIONAL'], countries: ['UK']} },
        { hospital: 'HKUniversity', imageSrc: require('@/assets/IndustryThinkTank/Tank3.png'), match: {regions: ['CHINA'], countries: ['HK']} },
        // 省略其他医院数据
      ],
      // 筛选后的医院数据
      filteredItems: [],
      // 筛选后的国家/省份数据
      filteredCountries: []
    };
  },
  created() {
    this.filterItems(); // 组件创建时筛选医院
    this.updateFilteredCountries(); // 组件创建时更新国家/省份列表
  },
  watch: {
    selectedRegion() {
      this.updateFilteredCountries(); // 当选中的地域发生变化时，更新国家/省份列表
    }
  },
  methods: {
    // 选择地域
    selectRegion(region) {
      this.selectedRegion = region;
      this.selectedCountry = 'ALL'; // 重置选中的国家/省份
      this.filterItems(); // 筛选医院
      this.updateFilteredCountries(); // 更新国家/省份列表
    },
    // 选择国家/省份
    selectCountry(country) {
      this.selectedCountry = country;
      this.filterItems(); // 筛选医院
    },
    // 筛选医院数据
    filterItems() {
      this.filteredItems = this.items.filter(item => {
        const regionMatches = this.selectedRegion === 'ALL' || item.match.regions.includes(this.selectedRegion);
        const countryMatches = this.selectedCountry === 'ALL' || item.match.countries.includes(this.selectedCountry);
        return regionMatches && countryMatches;
      });
    },
    // 更新国家/省份列表
    updateFilteredCountries() {
      if (this.selectedRegion === 'ALL') {
        this.filteredCountries = this.countries;
      } else if (this.selectedRegion === 'INTERNATIONAL') {
        this.filteredCountries = this.countries.filter(c => ['ALL', 'UK'].includes(c.value));
      } else if (this.selectedRegion === 'CHINA') {
        this.filteredCountries = this.countries.filter(c => ['ALL', 'HK', 'GD'].includes(c.value));
      }
    }
  }
};
</script>


<style scoped>
.IndustryThinkTank {
  font-family: Arial, sans-serif;
}

.filter-section {
  margin-bottom: 1%;
}

.filter {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  font-size: 1.2vw;
}

.filter-item-region {
  display: flex;
  align-items: center;
  margin-bottom: 1%;
  font-size: 1.2vw;
}

.filter-item-country {
  display: flex;
  align-items: center;
  margin-top: -1%;
  font-size: 1vw;

}

.filter-label {
  margin-left: 1%;
  margin-right: 1rem;
  font-weight: bold;
  font-size: 1vw;
}

.button-group {
  display: flex;
  gap: 1vw;
}

button {
  background: none; /* 删除背景 */
  border: none; /* 删除边框 */
  color: #000000; /* 按钮文本颜色 */
  padding: 0.5rem 1rem; /* 内边距 */
  font-size: 1vw;
  cursor: pointer; /* 鼠标指针样式 */
  transition: color 0.3s ease; /* 颜色变化过渡 */

}

button.active {
  background-color: #92cafd;
  color: white;
}


.content-section {
  width: 100%;
  padding: 3% 8% 0 10%; /* 保持上下内边距，左右内边距增加 */
}

.container {
  max-width: 100vw; /* 占满父元素宽度 */
  padding: 0;
  margin: 0 auto; /* 保持居中 */
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr); /* 固定三列 */
  gap: 2%; /* 网格间距 */
}

.card {
  display: flex;
  flex-direction: column;
  background-color: #f3f4f6;
  color: #1f2937;
  width: 90%;
  height: 90%;
  top: 2%;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.card:hover {
  transform: translateY(-10px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.card-image {
  height: 80%; /* 保持图片部分的高度 */
}

.card-image .image {
  width: 100%;
  height: 100%;
  object-fit: cover; /* 保持图片覆盖容器的上半部分 */
}

.card-content {
  padding: 1rem; /* 保持内边距 */
}

.location {
  display: flex;
  align-items: center;
  margin-bottom: 0.5rem;
  font-size: 1vw;
}

.hospital {
  font-weight: bold;
  font-size: 1vw;
}

@media (max-width: 768px) {
  .grid {
    gap: 1.5rem; /* 调整小屏幕上的网格间距 */
  }
}

@media (max-width: 480px) {
  .location {
    font-size: 10px; /* 调整字体大小 */
  }

  .hospital {
    font-size: 14px; /* 调整字体大小 */
  }
}
</style>
